#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int minimumOperationsToWriteY(vector<vector<int>>& grid) {
        int n = grid.size();
        int m = grid[0].size();
        int cnt1[3] = { 0 };
        int cnt2[3] = { 0 };

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if ((i == j && i <= n / 2) || (i + j == n - 1 && i <= n / 2) || (j == n / 2 && i >= n / 2))cnt1[grid[i][j]]++;
                else cnt2[grid[i][j]]++;
            }
        }

        int ans = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i != j) {
                    ans = max(ans, cnt1[i] + cnt2[j]);
                }
            }
        }
        return n * n - ans;
    }
};